package com.ktjy.controller;

import com.ktjy.entity.SysUser;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import java.util.AbstractCollection;
import java.util.Map;

@Controller
@RequestMapping("/dev")
public class HelloController {
    private static final Logger LOGGER = LoggerFactory.getLogger(HelloController.class);

    @RequestMapping("/hello")
    protected ModelAndView hello(@RequestParam(value = "realName", required = false) String name) throws Exception {
        LOGGER.info("你好{}欢迎学习SpringMVC!", name);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("realName", name);
        modelAndView.setViewName("hello");
//        LOGGER.info("Spring MVC框架搭建成功,当前请求路径:{}", request.getRequestURI());
        return modelAndView;
    }

    @RequestMapping("/model")
    protected String model(Model model, @RequestParam(value = "realName", required = false) String name) throws Exception {
        LOGGER.info("你好{},在参数注入Model对象也可以出参!", name);
        model.addAttribute("realName", name);
        SysUser user = new SysUser();
        user.setRealName(name);
        model.addAttribute("user", user);
        return "hello";
    }

    @RequestMapping("/map")
    protected String map(Map map, @RequestParam(value = "realName", required = false) String name) throws Exception {
        LOGGER.info("你好{},在参数注入Map对象也可以出参!", name);
        map.put("realName", name);
        SysUser user = new SysUser();
        user.setRealName(name);
        map.put("user", user);
        return "hello";
    }

    @RequestMapping("/welcome")
    protected String welcome(HttpServletRequest request) throws Exception {
        LOGGER.info("Spring MVC框架搭建成功,当前请求路径:{}", request.getRequestURI());
        return "hello";
    }
}
